package com.fly.estore.service.Impl;

import com.fly.estore.dao.MemberPointDAO;
import com.fly.estore.domain.MemberPoint;
import com.fly.estore.framework.util.CommonUtil;
import com.fly.estore.service.PointService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * Created by Fly on 2016/5/10.
 */
@Service("PointService")
public class PointServiceImpl implements PointService {

    @Autowired
    MemberPointDAO memberPointDAO;

    public int saveMemberPoint(MemberPoint point) {
        int update = 0;
        if (StringUtils.isBlank(point.getMemberPointId())){
            point.setMemberPointId(CommonUtil.genPK());
            update = memberPointDAO.addMemberPoint(point);
        }
        else{
            update = memberPointDAO.updateMemberPoint(point);
        }
        return update;
    }

    public int deleteMemberPointById(String memberPointId) {
        return memberPointDAO.deleteById(memberPointId);
    }

    public int deleteMemberPointByMemberId(String memberId) {
        return memberPointDAO.deleteByMemberId(memberId);
    }

    public int getMemberPoint(String memberId) {
        return memberPointDAO.getMemberPoint(memberId);
    }

    public List<MemberPoint> getMemberPointByMemberId(String memberId) {
        return memberPointDAO.getListByMemberId(memberId);
    }
}
